<?php 
session_start(); 
require_once('../include/connect.inc.php');
require_once('../include/layout-jquery.php');
$r_teacher_id=$_SESSION['id'];
if($_SESSION['sess_id'] <> session_id()){
?>
 <SCRIPT LANGUAGE="JavaScript">
			alert("กรุณาเข้าสู่ระบบให้ถูกต้องตามขั้นตอน...!");
			location="login.php";
</script>
<?php }?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Model Test Program</title>
<link rel="stylesheet" type="text/css" href="../template/template_style_wood.css">
<script type="text/javascript" src="../js/exam/show_question.js"></script>
<script language = "JavaScript">
$(document).ready(function() {
	  // Handler for .ready() called.
});
</script>
</head>

<body>
<div id="menu"><div><img src="../images/icon-m.png" /></div>
<div id="menulinks">
		<a  href="../person_tea.php">ข้อมูลส่วนตัว</a>
		<a href="../tea_edit.php">เปลี่ยนรหัสผ่านใหม่</a>
        
        <a href="show_subject.php">จัดการรายวิชา</a>
		<a class="active" href="../teacher_test.php">จัดการข้อสอบ</a>
        <a href="../teacher_tests.php">จัดการชุดข้อสอบ</a>
        <a  href="../agree_set.php">กำหนดสิทธิ์</a>
		<a href="../exam/tea_chack.php">ตรวจสอบคะแนน</a>
        <a href="../news/manage_news.php">ประกาศข่าวสาร</a>
        <a href="../problem/send_problem.php">แสดงความคิดเห็น</a>
        <a href="../logout.php">ออกจากระบบ</a>
		</div></div>           
 <div id="p3">    
<div id="header"></div>
   <div id="page"><div id="p1">คุณ<?php echo $_SESSION['teacher_name'];?><hr/>
<script language="javascript">
		function fncSubmit()
		{
		if(document.form1.subject.value=="0"){
				alert('กรุณาเลือกวิชา');
				document.form1.subject.focus();
				return false;
			}
			if(document.form1.topic.value=="0"){
				alert('กรุณาเลือกหัวข้อ');
				document.form1.topic.focus();
				return false;
			}
			if(document.form1.type_id.value == "0"){
				alert('กรุณาเลือกประเภทข้อสอบ');
				document.form1.type_id.focus();       
				return false;
			}  
			document.form1.submit();
	}
</script>
<table class="p21" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <th align="left"><font size="+1">แสดงข้อสอบ</font></th>
        <th align="left"><a href="../teacher_test.php"><img src="../images/undo.png" border="0" /></a></th>
      </tr>
</table>
<form id="form1" name="form1" method="post" action="frm_show_question.php?action=start" onSubmit="JavaScript:return fncSubmit();">
  <table class="p21" cellpadding="0" cellspacing="0">
  		<tr>
        	<th align="right">เลือกวิชา :</th>
      		<td><select id="subject" name="subject" onchange = "listTopic(this.value)">
        <option selected="selected" value="0">======เลือก======</option>
        <?php
	$strSQL ="SELECT * FROM tb_agree_teacher
	Inner Join tb_subject ON  tb_subject.subject_id = tb_agree_teacher.subject_id where tb_agree_teacher.r_teacher_id='$r_teacher_id' ORDER BY tb_subject.subject_id ASC";
	$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
	while($objResult = mysql_fetch_array($objQuery))
	{
	?>
        <option value="<?=$objResult["subject_id"];?>">
        <?=$objResult["subject_name"];?>
        </option>
        <?php
	}
	?>
      </select></td>
    </tr>
    <tr>
      <th align="right">เลือกหัวข้อ :</th>
      <td>
      		<select id="topic" name="topic" style="width:150px">
     			<option selected="selected" value="0">=================</option>
      		</select>
      </td>
      </tr>
      <tr>
      <th align="right">ประเภทข้อสอบ : </th>
      <td>
      	<select name="type_id" id="type_id">
    	   <option selected value="0">======เลือก======</option>
        <?php  
			$query = query("SELECT * FROM tb_type");
				while ($rs2 = fetch_array($query)) {
	  	?>
        <option value="<? echo $rs2[type_id]; ?>"><? echo $rs2[type_name];?></option>
        <?php }?>
      </select></td>
      </tr>
    <tr>
    	<td colspan="2" align="center">
   		 <input type="submit" name="select" id="select" value="เลือก" />
    	<input type="reset" name="selectall" id="selectall" value="ยกเลิก" />
    </td></tr></table>
</form>

<?php if( $_GET[action]== 'start' ) { 
	if($_POST['type_id']==5){
		$match=1;
	}else{
		$match=0;
	}
//-----------------------------------------------ส่วนแสดงข้อสอบแต่ล่ะประเภท-----------------------------------------///// 
?>
<form id="form2" name="form2" method="post" action="">
ประเภทข้อสอบ : 
<?php 
			$query = query("SELECT * FROM tb_type WHERE type_id=' ".$_POST[type_id]." ' ");
				while ($rs= fetch_array($query)) {
					$type_name=$rs['type_name'];
			?>
		<?php echo "$type_name"?>
 <? }?> 
<input type="hidden" name="set_cho" id="set_cho" value="<?php echo $match_set?>"/>
<?php }?>
<?php
	$number = 0;
	$type_id  = (int)$_POST['type_id'];
	$query2 = query("SELECT * FROM tb_question where topic_id='$topic' and type_id='$type_id' and type_id<>'5' ");
			$count=1;
			while ($rs2 = fetch_array($query2)){
				$question_id=$rs2['question_id'];
				$media_name=$rs2['media_name'];
				$number++;
			?>
     <div class="p21">
  		<table width="80%" border="0" cellpadding="0" cellspacing="0"  id="table-a"  summary="2007 Major IT Companies Profit">
    		<tr>
      		<td width="207">
        	<b>
        	<input type="hidden" name="question_id[]" id="question_id[]" value="<? echo $rs2[question_id ]?>" />               
        		<input type="hidden" name="set" id="set" value="<? echo $rs1[set_id]?>" />
<?php  
		echo $number; echo "."; echo $rs2['question_detail'];
?>
        <?php
			$query3 = query("SELECT * FROM tb_choice  where question_id =' " .$rs2['question_id']." ' ");
				while ($rs3 = fetch_array($query3)){
			?>
        <div class="p21"><?php  if($rs2['type_id']==2){?>
                <label>
                <input type="checkbox" name="choice[]<?=$count?>"  value="<?php echo $rs3[choice_id];?>" <?php if  ($rs3['answer']==1){?> checked="checked" <?php }?> disabled="disabled">
                </label>
                <?php } elseif($rs2['type_id']!=5){ ?>
                <label>
                <input type="radio" name="choice[]<?=$count?>"  value="<?php echo $rs3[choice_id];?>" <?php if  ($rs3['answer']==1){?> checked="checked" <?php }?> disabled="disabled">
                </label>
                <?php } ?>
                <?php  
				if($rs2['type_id']==5){
					echo "";
				}else{
					echo $rs3['choice_detail'];
				}
				?>
                </div>
        <?php } ?>
        </td>
		<td width="44" >
			<a href="frm_del_question.php?del_id=<?php echo $question_id;?>" onClick="return confirm('การลบข้อสอบมีผลต่อการดูผลคะแนนย้อนหลัง ยืนยันการลบข้อสอบ')"><img src="../images/delete1.png" border="0" /></a>        </td>
       <td width="44" >
         <a href ="frm_edit_question.php?question_id=<?php echo $question_id;?>"> <img src="../images/edit.png" border="0" /></a>       </td>  
        <td width="192">
        <?php  if($rs2['pic_name']!=""){?>
			<div align="center"><a href="../upload/<? echo  $rs2['pic_name'];?>" target="_blank">
				<img src="../upload/<? echo  $rs2['pic_name'];?>" border="0" width=50 height=50 
				onclick="window.open('../upload/<? echo  $rs2['pic_name'];?>','mywindow','width=500,height=500')" /></a>
				<div>
    				<small>คลิ๊กที่รูปเพื่อดูขนาดใหญ่</small>
				</div>
			</div>
		<? }?>
<?php  if($rs2['media_name']!=""){?>
<table align="center">
	<tr>
		<th>
        	<object id="mediaPlayer" height="23" width="80" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95">
            	<param name="fileName" value='<?php echo "../upload/$media_name";?>' valuetype='ref' />
                <param name="AutoStart" value="0" />
				<param name="TransparentAtStart" value="true" />
				<param name="SendPlayStateChangeEvents" value="true" />
				<param name="ShowControls" value="0" />
				<param name="ShowDisplay" value="0" />
				<param name="ShowStatusBar" value="1" />
				<param name="ShowGotoBar" value="0" />
				<param name="ShowPositionControls" value="0" />
				<param name="AutoSize" value="0" />
				<param name="volume" value="0" />
				<param name="loop" value="0" />
			</object>
		</th>
	</tr>
	<tr>
		<th align="right">
        	<img style="CURSOR: pointer" 
				onclick="mediaPlayer.play()" height="30" 
				src="../soundbox/play-48x48.png" 
				width="30" /><img style="CURSOR: pointer" 
				onclick="mediaPlayer.pause()" height="30" 
				src="../soundbox/puse-48x48.png" 
				width="30" /><img 
                src="../soundbox/stop-48x48.png" 
				width="30" height="30" style="CURSOR: pointer" 
				onclick="mediaPlayer.stop()" />
			</th>
	</tr>
</table>
<?php }?>
</td>      
            </tr>
          </table>
        </div>
          <?php $count++; //}?>
  		</td>
    </tr>
  </table>
<?php } ?>
<?php  if($match==1){?>
<?php
$A=0;
$queryD = query("SELECT DISTINCT match_set FROM tb_question where match_set!='NULL' and topic_id=$topic");
	while ($rsD = fetch_array($queryD)){
		$match_set=$rsD['match_set'];
		$A++;
		?>
<table border="0" cellpadding="0" cellspacing="0"  id="table-m" >
	<tr>
      <td width="200"><font size="+2"><strong>คำถาม</strong></font></td>
      <td width="200"><font size="+2"><strong>คำตอบ</strong></font></td>
      <td width="200"><font size="+2"><strong>ข้อลวง</strong></font></td>
      <td></td>
    </tr>
<?php 
$num=0;
$queryQ= query("SELECT * FROM tb_question where match_set=$match_set");
		while ($rs = fetch_array($queryQ)) {
			$question_id=$rs['question_id'];
			$question_detail=$rs['question_detail'];
			$num++;
?>
    <tr>
		<td>ข้อที่<?php echo $num?>) <?php echo "$question_detail";?></td>
      	<td>
<?php 
	$queryC= query("SELECT * FROM tb_choice where match_set=$match_set and question_id=$question_id and answer!=0");
		while ($rs = fetch_array($queryC)) {
			$choice_id=$rs['choice_id'];
			$choice_detail=$rs['choice_detail'];
?>
			คำตอบข้อที่ <?php echo $num?>) <?php echo "$choice_detail";?>
<?php }?>
       </td>
<td>
<?php }?>
<table border="0">
	<tr>
    	<th>
<?php
$numlie=0;
	$querylie= query("SELECT * FROM tb_choice where match_set=$match_set and answer=0");
		while ($rs = fetch_array($querylie)){
			$choice_id=$rs['choice_id'];
			$choice_detail=$rs['choice_detail'];
			$numlie++;
			?>
           <font size="+1">ข้อลวงที่ <?php echo $numlie?>) <?php echo "$choice_detail";?></font>
		</th>
        <?php }?>
      </tr>
   </table>
</td>
       <td align="center"><a href="frm_del_ques_set.php?del_id=<?php echo $match_set;?>" onClick="return confirm('การลบข้อสอบมีผลต่อการดูผลคะแนนย้อนหลัง ยืนยันการลบข้อสอบ')"><img src="../images/delete1.png" border="0" /></a>
        </td>
    </tr>
</table> 
<?php }?>
<input type="hidden" name="set_cho" id="set_cho" value="<?php echo $match_set?>"/>
<? }?>
</form>
    </div>
    </div>
<div id="footer"></div>
</div>
</body>
</html>